package leetcode_0643

func findMaxAverage1(nums []int, k int) float64 {

	sum := 0
	for i := 0; i < k; i++ {
		sum += nums[i]
	}
	maxSum := sum
	left, right := 0, k-1
	for {
		right++
		if right >= len(nums) {
			break
		}
		sum = sum - nums[left] + nums[right]
		if maxSum < sum {
			maxSum = sum
		}

		left++
	}

	return float64(maxSum) / float64(k)
}
